﻿import cv2
import numpy as np
from sys import argv
import base64
import os
import time
def main():
    url=["rtsp://admin:admin@191.18.89.8/cam/realmonitor?channel=1&subtype=0","rtsp://admin:admin@191.18.89.8/cam/realmonitor?channel=2&subtype=0"]
    now = time.strftime("%Y-%m-%d",time.localtime(time.time()))
    tt = "D:/Users/User/Desktop/chwh/zs/"+'/'+now
    tt1 = "D:/Users/User/Desktop/chwh/zs/tt"
    #清空tt文件夹下所有jpg文件
    for root,dirs,files in os.walk(tt1):
        for name in files:
            if name.endswith(".jpg"):
                os.remove(os.path.join(root,name))
    if not os.path.exists(tt):
        os.makedirs(tt)
#抓取第300帧图片
    for each in url:
        cap = cv2.VideoCapture(each)
        print(each)
        ip = each[-50:-36]
        tdh = each[-11]
        for i in range(300,301):
            ret,frame = cap.read()
            ret,arr = cv2.imencode('.jpg', frame)
            a = arr.tostring()
            fp = open(tt+'/'+ip+tdh+'.jpg', 'wb')
            fp.write(a)
            fp.close()
            fp = open(tt1+'/'+ip+tdh+'.jpg', 'wb')
            fp.write(a)
            fp.close()
        fps = cap.get(5)
        print(fps)
        cap.release()

if __name__ == '__main__':
    main()